package com.haiyou.dc.netty.controller.im;

import com.haiyou.common.util.R;
import com.haiyou.dc.netty.entity.ImUser;
import com.haiyou.dc.netty.service.ImUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author root
 * @date 2020-02-29 22:49:56
 */
@RestController
@RequestMapping("/im/user")
@Slf4j
@Api(tags = "APP用户控制器")
public class ImChatUserApi {

    @Autowired
    private ImUserService imUserService;

    @ApiOperation(value = "保存数据")
    @PostMapping("/login")
    public R login(@RequestBody ImUser imUser) {
        ImUser queryUser = new ImUser();
        queryUser.setUsername(imUser.getUsername());
        ImUser loginUser = imUserService.selectOne(queryUser);
        if (loginUser == null) {
            return R.error("账号或者密码错误");
        }
        if (!loginUser.getPassword().equals(imUser.getPassword())) {
            return R.error("账号或者密码错误");
        }
        return R.ok(loginUser);
    }

}